﻿/****************************************************************************
Copyright (c) 2014-2015 凌惊雪 微信:Lingjingxue 邮箱:lingjingxue@sina.com QQ:271487457

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/

using ServerBase.LunarSocket;
using ServerBase.Protocol;
using UtilLib;
using static ServerBase.Config.Conf;
using static ServerBase.Service.BaseDispatch;
using static UtilPublic.Redis.ServerRedis;
using ServerGame.Service;
using System.Collections.Generic;
using UtilPublic.ServerLoger;
using ServerBase.Service;
using ServerBase.Config;
using static ServerGame.Service.Dispatcher;
using ServerBase.Client;
using System;
using ServerPublic.Data;
using ServerGame.GameObject;
using static UtilPublic.Serialization.Jsh;
using ServerPublic.DataBaseMysql;
using UtilPublic.ApiDispatcher;
using ServerGame.Data;
using static ServerGame.Manager.Efun;
using System.Linq;

namespace ServerGame.Manager
{
    public partial class DispatcherMsg
    {
        [ApiDpPro((short)EProtocolId.C2G_CHAR_SCORE, "角色属性")]
        public short OnCharScore()
        {
            var player = (Player)ThisSession.SessionObj;
            (var Req, var Rsp) = ThisReq.Body.OnCharScore();

            player.GetInfo(Rsp.InfoScore);

            return Send(Rsp);
        }
        [ApiDpPro((short)EProtocolId.C2G_CHAR_OFFLINEINFO, "挂机信息")]
        public short OnCharOfflineInfo()
        {
            var player = (Player)ThisSession.SessionObj;
            (var Req, var Rsp) = ThisReq.Body.OnCharOfflineInfo();

            player.GetInfo(Rsp.InfoOffline);

            return Send(Rsp);
        }
        [ApiDpPro((short)EProtocolId.C2G_CHAR_OFFLINE, "挂机")]
        public short OnCharOffline()
        {
            var player = (Player)ThisSession.SessionObj;
            (var Req, var Rsp) = ThisReq.Body.OnCharOffline();

            Rsp.OfflineMode = Req.OfflineMode;
            if (player.DaBasic.OfflineMode == 0)
            {
                if (Req.OfflineMode == 0)
                {
                    Rsp.MessageFail("当前没有在挂机"); return Send(Rsp);
                }
            }
            else
            {
                if (Req.OfflineMode != 0)
                {
                    Rsp.MessageFail("当前正在挂机中"); return Send(Rsp);
                }
            }

            player.DaBasic.OfflineMode = Req.OfflineMode;
            player.DaBasic.OfflineTicks = DateTime.Now.Ticks;

            player.GetInfo(Rsp.InfoOffline);

            return Send(Rsp);
        }
        [ApiDpPro((short)EProtocolId.C2G_CHAR_LOOK, "查看")]
        public short OnCharLook()
        {
            var player = (Player)ThisSession.SessionObj;
            (var Req, var Rsp) = ThisReq.Body.OnCharLook();

            Rsp.Uid = Req.Uid;
            if (!player.Room.DictPlayer.TryGetValue(Req.Uid, out var ppp))
            {
                Rsp.MessageFail("没有这个玩家"); return Send(Rsp);
            }
            Send(Rsp);

            bool lookself = (ppp.Puid == player.Puid);
            if (!lookself)
            {
                ppp.Message($"{player.Name}正盯着你看，不知道打些什么主意。");
            }
            var pro = lookself ? GenderSelf(ppp.Gender) : GenderPronoun(ppp.Gender);
            player.Message(ppp.Desc);
            if (ppp.Age < 10)
            {
                player.Message($"{pro}看起来显然还不到十岁。");
            }
            else
            {
                player.Message($"{pro}看起来约{ChineseNumber(ppp.Age / 10 * 10)}多岁。");
            }
            if (ppp.Level > player.Level * 3)
            {
                player.Message($"{pro}的修为看起来似乎#HIW#无法估量#NOR#。");
            }
            else
            {
                player.Message($"的修为看起来{DescLevel(ppp.Level)}。");
                player.Message($"出手似乎{DescDamage(ppp[EProp.damage])}。");
            }
            var descper = DescPer(ppp.Age, ppp.Gender, ppp[EProp.per] + ppp[EProp.adper]);
            player.Message($"{pro}{descper}");
            player.Message($"{pro}{DescKee(ppp[EProp.kee], ppp[EProp.mxkee])}");

            return 0;
        }
        [ApiDpPro((short)EProtocolId.C2G_CHAR_INV, "背包")]
        public short OnCharInv()
        {
            var player = (Player)ThisSession.SessionObj;
            (var Req, var Rsp) = ThisReq.Body.OnCharInv();

            player.DaCommon.DictItem.ItemInfo(ref Rsp.DictItem);
            player.EquipInfo(ref Rsp.DictEquip);
            player.WearInfo(ref Rsp.DictWear);

            return Send(Rsp);
        }

    }
}
